#include <iostream>
#include <list>
using namespace std;

class LockersDivTwo {
public:
    int lastOpened(int N) {
        typedef list<int> TList;
        TList lst(N);
        int counter = 1;
        for (TList::iterator it = lst.begin(); it != lst.end(); ++it, ++counter)
            *it = counter;
   
        int res = -1;
        for (int s = 1; lst.size(); ++s) {
            int steps = 0;
            for (TList::iterator it = lst.begin(); it != lst.end(); ++it, ++steps) {
                if (steps % s == 0) {
                    res = *it;
                    TList::iterator tmpIter = it;
                    ++it;
                    lst.erase(tmpIter);
                    if (it == lst.end())
                        break;
                }
            }

        }
        return res;
    }
};

int main() {
    cout << "<<<test>>>" << endl;
    LockersDivTwo obj;
    int N = -1;
    cin >> N;
    cout << endl;
    cout << "input=" << N << endl
         << "result=" << obj.lastOpened(N) << endl;
    return 0;
}
